﻿using System.Collections.Generic;
using System.Text;
using System.Web.Mvc;
using System.Web.Routing;
using Common.Objects.Column;
using Common.Resources;

namespace Common.Helpers
{
    public static class RenderColumnHelper
    {
        public static MvcHtmlString RenderColumn(this HtmlHelper helper, IBaseColumn column, object htmlAttributes = null)
        {
            return new MvcHtmlString(column.Render());
        }

        public static MvcHtmlString RenderRow(this HtmlHelper helper, IList<IBaseColumn> columns, object htmlAttributes = null)
        {
            TagBuilder tagBuilder = new TagBuilder("tr");
            tagBuilder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
            tagBuilder.AddCssClass(HtmlResources.SelectRowClassName);
            foreach (var item in columns)
            {
                tagBuilder.InnerHtml += helper.Raw(item.Render());
            }
            
            
            return new MvcHtmlString(tagBuilder.ToString(TagRenderMode.Normal));
        }
    }
}